﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//buddy
using Zeta;
using Zeta.Common;
using Zeta.CommonBot;
using Zeta.Common.Plugins;
using Zeta.Internals;
using Zeta.Internals.Actors;
using Zeta.Internals.Service;

namespace BossHog.ProfileBuilder
{
    public class WhileElement : IOrderChildElement, ICommand
    {
        public WhileElement() { Commands = new List<IOrderChildElement>(); }
        public string condition { get; set; }
        public List<IOrderChildElement> Commands { get; set; }
        public override string ToString()
        {
            if (null == Commands || Commands.Count < 1) return "<While condition=\"" + condition + "\"></While>";

            StringBuilder tmp = new StringBuilder();
            tmp.AppendLine("<While condition=\"" + condition + "\">");
            for (int i = 0; i < Commands.Count; i++)
            {
                tmp.AppendLine(Commands[i].ToString());
            }
            tmp.AppendLine("</While>");
            return tmp.ToString();
        }

        public void Write(System.Xml.XmlTextWriter w)
        {
            Type t = this.GetType();
            w.WriteStartElement("While");
            if (!string.IsNullOrWhiteSpace(condition) && !string.IsNullOrEmpty(condition))
            {
                w.WriteStartAttribute("condition");
                w.WriteValue(condition);
                w.WriteEndAttribute();
            }
            if (null != Commands && Commands.Count > 0)
            {
                for (int i = 0; i < Commands.Count; i++)
                {
                    Commands[i].Write(w);
                }
            }
            w.WriteEndElement();
        }

    }

}
